<?php
/*********************************************
  Dragonfly CMS, Copyright (c) 2004 by CPGNuke Dev Team
  http://dragonflycms.org
  Released under GNU GPL version 2 or any later version
**********************************************/
if (!defined('CPG_NUKE')) { exit; }
require('includes/cmsinit.inc');
if (DF_HTTP_SSL_REQUIRED && 'https' !== DOMAIN_PROTOCOL) {
	URL::redirect('https://'. DOMAIN_NAME. URL::uri());
}
if (URL::query() && URL::query() != URL::canonical())
{
	URL::redirect(BASEHREF.URL::canonical(), false, 301);
}

//header('X-Content-Type-Options: nosniff'); sent already from bootstrap

if ($SESS->new && $MAIN_CFG['global']['httpref'] && isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
	$referer = Fix_Quotes($_SERVER['HTTP_REFERER']);
	if (strpos($referer, '://') && !stripos($referer, $MAIN_CFG['server']['domain'])) try {
		if (!$db->exec('UPDATE '.$prefix.'_referer SET lasttime='.time().' WHERE url=\''.htmlprepare($referer).'\'')) {
			$db->query("INSERT INTO {$db->TBL->referer} (url, lasttime) VALUES ('".htmlprepare($referer)."', ".time().")");
		}
		$numrows = $db->count('referer');
		$httprefmax = (int)$MAIN_CFG['global']['httprefmax'];
		if ($numrows >= $httprefmax) {
			$db->query("DELETE FROM {$db->TBL->referer} ORDER BY lasttime LIMIT ".($numrows-($httprefmax/2)));
		}
	} catch (Exception $e){}
}

/* mid needs work, temporary expanded for readibility */
Module::$custom[-2] = array(
	'mid' => -2,
	'get' => 'credits',
	'title' => 'credits',
	'file' => 'includes/info.inc',
	'view' => 0,
	'blocks' => Blocks::NONE);
Module::$custom[-3] = array(
	'mid' => -3,
	'get' => 'privacy_policy',
	'title' => 'privacy_policy',
	'file' => 'includes/info.inc',
	'view' => 0,
	'blocks' => Blocks::NONE);
Module::$custom[-4] = array(
	'mid' => -4,
	'get' => 'smilies',
	'title' => 'smilies',
	'file' => 'includes/nbbcode.php',
	'view' => 1,
	'blocks' => Blocks::NONE);
Module::$custom[-5] = array(
	'mid' => -5,
	'get' => 'user_search',
	'title' => 'user_search',
	'file' => 'includes/user_search.inc',
	'view' => 1,
	'blocks' => Blocks::NONE);

$Module = new Module('name', 'file');
if (!is_file($Module->path.$Module->file)) {
	cpg_error(sprintf(_MODULENOEXIST, CPG_DEBUG ? $Module->path.$Module->file : ''), 404);
}
# check for permissions
$Module->allow();

/* compatibility */
$home = $Module->in_home && empty($_GET['name']);
$module_name = $Module->name;
$showblocks = &$Module->sides;
$module_title = $Module->title;
/* end compatibility */

# get module custom language
//Dragonfly::getKernel()->L10N->load($Module->name);

# good place where to run hooks
Dragonfly::getKernel()->extend('SOCIAL', '\Dragonfly\Social');
//$GLOBALS['DF']->setState(DF::PRE_MODULE);

//MetaTag::add(Module::$metatag); // must include Page data already
include('includes/meta.php');
require($Module->path.$Module->file);

if (defined('HEADER_OPEN')) { require_once('footer.php'); }
